package com.modifymetrodemo.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;

public class SharedPreferenceUtils {

    private static final String CHOSEN_BUSINESS_ASSERT_PATH = "chosenBusinessAssertPath";
    private static final String CHOSEN_BUSINESS_MAIN_COMPONENT_NAME = "chosenBusinessMainComponentName";


    public static void saveChosenBusinessAssetsPath(Context context, String bussiness){
        putStringValue(context, CHOSEN_BUSINESS_ASSERT_PATH,bussiness);
    }

    public static String getChosenBusinessAssetsPath(Context context){
        return getSharedPreferences(context).getString(CHOSEN_BUSINESS_ASSERT_PATH,"");
    }

    public static void saveChosenBusinessMainComponentName(Context context, String componentName){
        putStringValue(context, CHOSEN_BUSINESS_MAIN_COMPONENT_NAME, componentName);
    }

    public static String getChosenBusinessMainComponentName(Context context){
        return getSharedPreferences(context).getString(CHOSEN_BUSINESS_MAIN_COMPONENT_NAME, "");
    }


    public static boolean hasChosenBusinessAssetsPath(Context context){
        return !TextUtils.isEmpty(getChosenBusinessAssetsPath(context));
    }

    /**
     * Base Methods
     */
    private static SharedPreferences getSharedPreferences(Context context) {
        SharedPreferences preferences = context.getApplicationContext().getSharedPreferences("RNTest", Context.MODE_PRIVATE);
        return preferences;
    }

    private static void putStringValue(Context context, String key, String value) {
        SharedPreferences preferences = getSharedPreferences(context);
        preferences.edit().putString(key, value).commit();
    }

}
